import request from './request'
import apiUrls from './apiUrl'
import useDictStore from '@/store/dict.js'
export default {
	// 从缓存加载字典数据
	loadData(dictType) {
		const dicts = useDictStore().getDict(dictType);
		return new Promise((resolve, reject) =>{
			if (dicts) {
				resolve(dicts);
			} else {
				request(apiUrls.system.dict.getDicts + dictType,{}, 'GET').then(res => {
					if (res.data) {
						res.data.forEach(e => {
							e.text = e.dictLabel
							e.value = e.dictValue
						})
						useDictStore().setDict(dictType, res.data);
						resolve(res.data);
					}
				})
			}
		})
	
	}
}
